﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace SilverlightApplication
{
    public partial class Page : UserControl
    {

        public Page()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Page_Loaded);
            upDateCities("uk");
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            System.Windows.Browser.HtmlPage.RegisterScriptableObject("MySilverlightObject", this);
        }

        [ScriptableMember]
        private void upDateCities(string strCountry)
        {
            List<CityData> myCities = getCities(strCountry);
            itmCities.ItemsSource = myCities;
        }

        private List<CityData> getCities(string strCountry)
        {
            List<CityData> ret = new List<CityData>();
            switch (strCountry)
            {
                case "france":
                    {
                        ret.Add(new CityData("Paris", 48.87, 2.33));
                        ret.Add(new CityData("Lourdes", 43.1, 0.05));
                        ret.Add(new CityData("Toulouse", 43.6, 1.38));
                        break;
                    }
                case "uk":
                    {
                        ret.Add(new CityData("London", 51.5, 0));
                        ret.Add(new CityData("Stratford-Upon-Avon", 52.3, -1.71));
                        ret.Add(new CityData("Edinburgh", 55.95, -3.16));
                        break;
                    }
                case "germany":
                    {
                        ret.Add(new CityData("Berlin", 52.52, 13.42));
                        ret.Add(new CityData("Munich", 48.13, 11.57));
                        ret.Add(new CityData("Hamburg", 53.58, 9.98));
                        break;
                    }
            }
            return ret;
        }

    }
}
